/* 基于 state 的计算属性 */
export default {
    // 获取购物车内的食品总数量
    totalCount(state) {
        // let result = 0
        // if (state.shopCart.length) {
        //     for(let i =0 ; i< state.shopCart.length ; i++) {
        //         result += state.shopCart[i].food.count
        //     }
        // }
        return state.shopCart.reduce((preTotal, food) => preTotal + food.count, 0)
        // return result
    },
    // 获取当前食品的总价格
    totalPrice(state) {
        return state.shopCart.reduce((preTotal, food) => preTotal + food.count*food.price , 0)
    },
    // 获取评论数量, 
    positiveSize(state) {
        return state.ratings.reduce((preTotal , rating) => preTotal + (rating.rateType === 0 ? 1 : 0), 0)
    }
}